package com.longcai.piaojia.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.conn.MyOrderListGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2016/8/4.
 */
public class TicketOrderListAdapter extends ArrayAdapter<MyOrderListGet.MyOrderEntity> {

    private Context context;
    private LayoutInflater layoutInflater;
    private int state;

    public TicketOrderListAdapter(Context context, List<MyOrderListGet.MyOrderEntity> objects) {
        super(context, 0, objects);

        this.context = context;

        layoutInflater = ((Activity) context).getLayoutInflater();
    }

    public void notifyDataSetChanged(int state) {

        this.state = state;

        notifyDataSetChanged();

    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;

        MyOrderListGet.MyOrderEntity myOrderEntity = getItem(position);

        if (convertView == null) {

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_ticket_order_list, null)));

            convertView.setTag(viewHolder);

        } else {

            viewHolder = (ViewHolder) convertView.getTag();

        }

        viewHolder.item_ticket_order_num_tv.setText(myOrderEntity.order_number);

        viewHolder.item_ticket_order_title_tv.setText(myOrderEntity.title);
        viewHolder.item_ticket_order_showtime_tv.setText(myOrderEntity.posttime);
        viewHolder.item_ticket_order_showaddress_tv.setText(myOrderEntity.place);

        switch (state) {

            case 0:

                viewHolder.item_ticket_order_state_tv.setText(context.getResources().getString(R.string.myorder_list_state_no_pay_text));

                break;
            case 1:

                viewHolder.item_ticket_order_state_tv.setText(context.getResources().getString(R.string.myorder_list_state_payed_text));

                break;
            case 2:

                viewHolder.item_ticket_order_state_tv.setText(context.getResources().getString(R.string.myorder_list_state_used_text));

                break;
            case 6:

                viewHolder.item_ticket_order_state_tv.setText(context.getResources().getString(R.string.myorder_list_state_pay_complete_text));

                break;

        }

        viewHolder.item_ticket_order_price_tv.setText(myOrderEntity.discount_price+context.getResources().getString(R.string.goods_info_money_text));

        GlideLoader.getInstance().get(context, myOrderEntity.picurl, viewHolder.item_ticket_order_iv, R.mipmap.goods);

        return convertView;

    }

    private class ViewHolder {

        @BoundView(R.id.item_ticket_order_num_tv) public TextView item_ticket_order_num_tv;
        @BoundView(R.id.item_ticket_order_state_tv) public TextView item_ticket_order_state_tv;
        @BoundView(R.id.item_ticket_order_iv) public ImageView item_ticket_order_iv;
        @BoundView(R.id.item_ticket_order_title_tv) public TextView item_ticket_order_title_tv;
        @BoundView(R.id.item_ticket_order_showtime_tv) public TextView item_ticket_order_showtime_tv;
        @BoundView(R.id.item_ticket_order_showaddress_tv) public TextView item_ticket_order_showaddress_tv;
        @BoundView(R.id.item_ticket_order_price_tv) public TextView item_ticket_order_price_tv;

    }


}
